package com.ruoyi.web.controller.saas;

import com.bonuo.saas.domain.LogBook;
import com.bonuo.saas.service.LogBookService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "日志管理")
@RestController
@RequestMapping("/saas/logBook")
public class LogBookController extends BaseController {

    @Autowired
    private LogBookService logBookService;

    @ApiOperation(value = "查询日志列表",httpMethod = "GET")
    @GetMapping("/list")
    public AjaxResult list(LogBook logBook, Integer pageNum, Integer pageSize){
        if(pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<LogBook> list = logBookService.selectLogBookList(logBook);
        return success(new PageInfo<>(list));
    }

    @ApiOperation(value = "添加日志",httpMethod = "POST")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LogBook logBook){
        Integer add = logBookService.insertLogBook(logBook);
        return toAjax(add);
    }

    @ApiOperation(value = "修改日志",httpMethod = "PUT")
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody LogBook logBook){
        Integer update = logBookService.updateLogBook(logBook);
        return toAjax(update);
    }

    @ApiOperation(value = "删除日志",httpMethod = "DELETE")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id){
        Integer delete = logBookService.deleteLogBookById(id);
        return toAjax(delete);
    }
}
